<style scoped>
  .app-container >>> .scode {
    cursor: pointer;
    color: #20B2AA;
    text-decoration: underline;
  }
  .app-container >>> .scodeth {
    color: #515a6e;
  }
</style>
<template>
  <div class="app-container">
    <el-form :model="queryParams " ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乙方"  prop="partb">
        <el-select v-model="queryParams.partb" clearable placeholder="请选择乙方" size="small">
          <el-option
            v-for="item in plantors"
            :key="item.id"
            :label="item.realname"
            :value="item.guid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="负责人"  prop="operatorid">
        <el-select v-model="queryParams.operatorid" clearable placeholder="请选择负责人" size="small">
          <el-option
            v-for="item in users"
            :key="item.guid"
            :label="item.realname"
            :value="item.guid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" >
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          unlink-panels
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="合同状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择合同状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="procurementcontractList" @selection-change="handleSelectionChange" border>
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="编号" align="center" prop="code" label-class-name="scodeth" class-name="scode">
        <template slot-scope="scope">
          <span @click="viewIt(scope.row.id)">{{ scope.row.code }}</span>
          <!--            <span>{{ scope.row.sellcode }}</span>-->
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="采收主体" align="center" prop="parta" />
      <el-table-column label="供应商" align="center" prop="supplierName" />
      <el-table-column label="地块" align="center" prop="arealandname" />
      <el-table-column label="产品" align="center" prop="productname" />
      <el-table-column label="规格" align="center" prop="specificationname" />
      <el-table-column label="单价(元/吨)" align="center" prop="price" />
      <el-table-column label="扣杂方式" align="center" prop="deducttypeName" />
      <el-table-column label="扣杂率" align="center" prop="discountrate" />
      <el-table-column label="创建人" align="center" prop="createName" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listProcurementcontract, getProcurementcontract} from "@/api/harvest/procurementcontract";
import { listOldUser } from "@/api/system/user";
import {getPlanters} from "@/api/pay/payinfo";

export default {
  name: "Procurementcontract",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同管理表格数据
      procurementcontractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 质检方式字典
      qatypeOptions: [],
      // 合同状态字典
      statusOptions: [],
      plantors: '',
      users: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        partb: null,
        code: null,
      },
      // 表单参数
      form: {},
      // 日期范围
      dateRange: [],
      // 表单校验
      rules: {
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        parta: [
          { required: true, message: "甲方不能为空", trigger: "change" }
        ],
        partb: [
          { required: true, message: "乙方不能为空", trigger: "change" }
        ],
        arealandid: [
          { required: true, message: "采收地块不能为空", trigger: "change" }
        ],
        price: [
          { required: true, message: "单价(元/吨)不能为空", trigger: "blur" }
        ],
        discountrate: [
          { required: true, message: "扣杂率不能为空", trigger: "blur" }
        ],
        qatype: [
          { required: true, message: "质检方式不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getPlantors();
    this.listOldUser();
    this.getDicts("quality_type").then(response => {
      this.qatypeOptions = response.data;
    });
    this.getDicts("harvest_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    viewIt(id) {
      this.$router.push({path: '/harvest/contractinfo', query: {id: id}});
    },
    listOldUser: function () {
      listOldUser().then(response => {
        this.users = response.data;
      });
    },
    getPlantors: function () {
      getPlanters().then(response => {
        this.plantors = response.data;
      });
    },
    /** 查询合同管理列表 */
    getList() {
      this.loading = true;
      listProcurementcontract(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.procurementcontractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 质检方式字典翻译
    qatypeFormat(row, column) {
      return this.selectDictLabel(this.qatypeOptions, row.qatype);
    },
    // 质检方式字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.qatype);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        guid: null,
        batchguid: null,
        name: null,
        parta: null,
        partb: null,
        arealandid: null,
        price: null,
        spotcheckrate: null,
        discountrate: null,
        createdate: null,
        operatorid: null,
        lastupdate: null,
        starttime: null,
        specificationid: null,
        qatype: "0",
        soilchkrate: null,
        unqualifiedchkrate: null,
        deducttype: 0,
        setlwgtype: null,
        organizationid: null,
        isdiscount: null,
        productguid: null,
        paymentmethod: 0,
        wghtperpkg: null,
        flowid: null,
        srguid: null,
        srname: null,
        code: null,
        status: 0,
        departid: null,
        departname: null,
        qamainid: null,
        type: null,
        farmerstoreid: null,
        farmerstore: null,
        spguid: null,
        specificationname: null,
        bank: null,
        bankcode: null,
        harvesttype: null,
        series: null,
        seriesname: null,
        region: null,
        regionname: null
      };
      this.resetForm("form");
      this.dateRange = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.guid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
